package com.yc.fedex.exceptions;

import lombok.Getter;

import javax.ws.rs.core.MultivaluedMap;
import java.util.List;

@Getter
public class FedexErrorResponseException extends RuntimeException {

    static final String MESSAGE = "Received unexpected Response Status Code of %d\nResponse Headers of:\n%s\nResponse Body of:\n%s";
    private final int statusCode;
    private final String responseBody;
    private final List<FedexError> fedexErrorCodes;

    public FedexErrorResponseException(int status, MultivaluedMap<String, String> headers, String responseBody) {
        super(String.format(MESSAGE, status, headers, responseBody));
        this.responseBody = responseBody;
        this.fedexErrorCodes = FedexErrorCodeFactory.create(responseBody);
        this.statusCode = status;
    }
}
